package com.sxz.sbs.module.staff;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.blankj.utilcode.util.ToastUtils;
import com.sxz.sbs.R;
import com.sxz.sbs.app.GlideApp;
import com.sxz.sbs.base.BaseActivity;
import com.sxz.sbs.event.OperateSuccessEvent;
import com.sxz.sbs.http.retrofit.HttpParamMap;
import com.sxz.sbs.module.staff.mode.StaffIntentBean;
import com.sxz.sbs.module.staff.presenter.StaffDimissionPresenter;
import com.sxz.sbs.module.staff.view.StaffDimissionView;
import com.sxz.sbs.widget.CommonTitle;
import org.greenrobot.eventbus.EventBus;
import java.util.HashMap;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * 员工离职界面
 *
 * @author Administrator
 */
public class StaffDimissionActivity extends BaseActivity<StaffDimissionPresenter> implements StaffDimissionView {

    @BindView(R.id.iv_dimission)
    ImageView ivDimission;
    @BindView(R.id.iv_dimission_name)
    TextView ivDimissionName;
    @BindView(R.id.iv_dimission_phone)
    TextView ivDimissionPhone;
    @BindView(R.id.tv_chose_result)
    TextView tvResult;
    private StaffIntentBean staffBean;
    private int selectedId;
    @Override
    protected void init() {
        staffBean = getIntent().getParcelableExtra("staff_dimission");
        if (staffBean != null) {
            new CommonTitle.Builder(this).setTitle("员工离职").build().show();
            GlideApp.with(this).load(staffBean.getHeadUrl()).placeholder(R.drawable.ic_headportrait)
                    .error(R.drawable.ic_headportrait).into(ivDimission);
            ivDimissionName.setText(staffBean.getStaffName());
            ivDimissionPhone.setText(staffBean.getStaffPhone());

        } else {
            new CommonTitle.Builder(this).setTitle("加载出错").build().show();
        }

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_staff_dimission;
    }

    @Override
    protected StaffDimissionPresenter createPresenter() {
        return new StaffDimissionPresenter();
    }


    @OnClick({R.id.rl_dimission_joint, R.id.btn_dimission})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.rl_dimission_joint:
                if (staffBean != null) {
                    startActivityForResult(new Intent(this,ChoseStaffActivity.class)
                    .putExtra("staff_bean",staffBean)
                    .putExtra("chose_tag",ChoseStaffActivity.CHOSE_STAFF_DIMISSION)
                    ,1002);
                }
                break;
            case R.id.btn_dimission:
                if (TextUtils.isEmpty(tvResult.getText().toString())) {
                    ToastUtils.showShort("请选择对接人");
                    return;
                }
                if (staffBean != null) {
                    HashMap<String,Object> map = HttpParamMap.getParamMap();
                    map.put("fid",staffBean.getDisposeId());
                    map.put("pid",staffBean.getParkingId());
                    map.put("ftid",selectedId);
                    mPresenter.staffDimission(map);
                }

                break;
            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null) {
            return;
        }
        if (requestCode == 1002 && resultCode == 1003) {
            tvResult.setText(data.getStringExtra("dimission_name"));
            selectedId = data.getIntExtra("dimission_id",0);
        }
    }

    @Override
    public void onStaffDimissionSuccess() {
        EventBus.getDefault().post(new OperateSuccessEvent());
        startActivity(OperateSuccessActivity.class);
        finish();
    }
}
